<?php

class kefuAction extends SaleAction
{
   public function index()
   {
       Load('extend');
       $kefuView = D("kefuView");
       $userid = I("session.userid");



       $query_type = I("get.query_type", 0);
       $query_userName = I("get.query_userName", "");
       if($query_userName=="0")
       {
           $query_userName="";
       }

       if (!mb_check_encoding($query_userName, 'utf-8')){
           $query_userName = iconv('gb2312', 'utf-8', $query_userName);
       }

       switch($query_type)
       {
           case "0":break;
           case "1": $condition["400tel"]= 1 ; break;
           case "2": $condition["website"]= 1 ; break;
           case "3": $condition["youhua"]= 1 ; break;
           case "4": $condition["yishangtong"]= 1 ; break;
       }
       $this->query_type = $query_type;

       if(!empty($query_userName))
       {
           $condition["company|cname"]=  array("exp", "like '%$query_userName%'"); ;
           $this->query_userName = $query_userName;
       }

       $condition["c.section"]=20;
       $condition["adduser"]=$userid;
       if($userid=="16")
           $condition["adduser"]=17;


       $query_isgiveup = I("get.query_isgiveup", 0);
       $condition["isgiveup"]=$query_isgiveup;
       $this->query_isgiveup=$query_isgiveup;

      // $custom_list=$kefuView->field('id,cname,company,tel,400tel,website,youhua,yishangtong')->where($condition)->order("addtime desc")->select();

       $pagenum = I("get.p");
       import("ORG.Util.Page");
       $pagsize=M('employee')->where('id='.I("session.userid"))->getField("pagesize");
       $totalnum=$kefuView->where($condition)->count();
       $list=$kefuView->where($condition)->page($pagenum)->order('id desc')->limit($pagsize)->select();
      // echo($kefuView->getLastSql());exit;
       $page=new Page($totalnum,$pagsize);
       $page->rollPage=$pagsize;
       $page->setConfig("prev","上一页");
       $page->setConfig("next","下一页");
       $page->setConfig("first","首页");
       $page->setConfig("last","末页");
       $page->setConfig("theme","共%totalRow%%header%条数据 %nowPage%/%totalPage%页  %first% %upPage%   %linkPage%  %downPage% %end%");

       unset($data);
       $pageshow = $page->show();
       $this->assign("pageshow", $pageshow);

       //echo($pageshow); exit;
       $this->custom_list=$list;
       $this->display();
   }

    public function addcustom()
    {
        $area=M("areas");
        $areaList=$area->where(" parent_id='291'")->select();
        $this->areaList=$areaList;

        //如果是编辑读取客户信息
        $id = $_GET['id'];
        if($id!="")
        {
            $this->action = "edit";
            $custom = M('Custom');
            $custom_item = $custom->where("id=$id")->find();
            $this->custom = $custom_item;
        }
        else
            $this->action = "add";

        $this->display();
    }

    public function showcustom()
    {
        $area=M("areas");
        $areaList=$area->where(" parent_id='291'")->select();
        $this->areaList=$areaList;

        //如果是编辑读取客户信息
        $id = $_GET['id'];
        $custom = M('Custom');
        $custom_item = $custom->where("id=$id")->find();
        $this->custom = $custom_item;

        $this->display();
    }

    public function save()
    {
        $newuser = D('Custom'); // 实例化模型类
        $data = $newuser->create();
        if (!$data) $this->error($newuser->getError());
        $myinfo = I("session.my_info");
        //dump($myinfo) ;

        $custominfo = $newuser->find($data['id']);
        if($custominfo!="")
        {
            if ($custominfo['adduser'] != $myinfo["id"])
            {
                $this->error("你不能编辑当前用户");
            }
        }

        $data["adduser"] = $myinfo["id"];
        $data["rname"] = $myinfo["name"];
        $data["section"] = '20';//$myinfo["department"];
        //客服部 录入的客户 默认department为客户部的id:20

        $data["area_id"]=I('post.area');
        $area=M("areas");
        $area_names=$area->where(" area_id='".$data['area_id']."'")->find();
        if($area_names!=null)
        {
            $data["area_name"]=$area_names["area_name"];
        }

        $action=I('post.action');
        if($action=="add")
        {
            if (!$newuser->add($data))
            {
                $this->error("提交失败");
            }
        }
        else
        {
            if(!$newuser->save($data))
            {
                $this->error("提交失败");
            }
        }


        $this->show('<script type="text/javascript" src="__PUBLIC__/libs/js/jquery.js"></script>
	   <script type="text/javascript">
	   $(function(){
		   top.Dialog.alert("成功提交",function(){
			   window.parent.frmright.location.reload();
			   top.Dialog.close()
	   })})</script>
	   ', 'utf-8');

        //window.location=" '. U('addcustom') .' ";

    }

    public function customdelete()
    {
        $id = I("get.id");
        $custom = M('Custom');

        if (!$custom->delete($id))
        {
            $this->error("删除失败");
        } else
        {
            $this->success("删除成功");
        }
    }

    public function customgiveup()
    {
        $id = I("get.id");
        $custom = M('Custom');
        $data = array('isgiveup' => "1");

        $tel400=M('400tel');
        $tel400->where("cid=$id")->save($data);

        $website=M('website');
        $website->where("cid=$id")->save($data);

        $youhua=M('youhua');
        $youhua->where("cid=$id")->save($data);

        $businessdata = array('400tel' => "0","website" => "0" ,"youhua"=>"0","yishangtong" =>"0");
        $custombusiness=M("custombusiness");
        $custombusiness->where("cid=$id")->save($businessdata);

        $custom->where("id=$id")->save($data); // 根据条件保存修改的数据
        $this->success('放弃成功');
    }

    public function tel400list()
    {
        Load('extend');
        $custom=M("custom");


        $condition["type"]=1;
        $huifangdata = $this->CacheArray("huifang", 'yewuid',$condition);
        $this->huifangdata = $huifangdata;

        $xufeidata = $this->CacheArray("xufei", 'yewuid',$condition);
        $this->xufeidata = $xufeidata;

        unset($condition);

        $query_userName = I("get.query_userName", "");
        if($query_userName=="0")
            $query_userName='';

        if (!mb_check_encoding($query_userName, 'utf-8')){
            $query_userName = iconv('gb2312', 'utf-8', $query_userName);
        }

        $query_sdate=I("get.query_sdate","1970-1-1");
        $query_edate=I("get.query_edate",date("Y-m-d H:i:s"));

        $this->query_userName=$query_userName;
        if($query_sdate!="0")
            $this->query_sdate=I("get.query_sdate");
        if($query_edate!="0")
            $this->query_edate=I("get.query_edate");

        if($query_sdate=="0")
            $query_sdate='1970-1-1';
        if($query_edate=="0")
            $query_edate= date("Y-m-d H:i:s");

        $query_isgiveup = I("get.query_isgiveup", 0);
        $condition["ys_400tel.isgiveup"]=$query_isgiveup;
        $this->query_isgiveup=$query_isgiveup;

        if(!empty($query_userName))
        {
            $condition["company|cname"]=  array("exp", "like '%$query_userName%'"); ;
            $this->query_userName = $query_userName;
        }

        $condition['_string'].=" to_days(signdate)>=to_days('$query_sdate') and to_days(signdate)<=to_days('$query_edate')";
        // $tel400List=$custom->join(" right join ys_400tel on ys_400tel.cid=ys_custom.id ")->where($condition)->select();
        $userid = I("session.userid");

        $condition["adduser"]=$userid;
        if($userid=="16")
            $condition["adduser"]="17";


        $pagenum = I("get.p");
        import("ORG.Util.Page");
        $pagsize=M('employee')->where('id='.I("session.userid"))->getField("pagesize");
        $totalnum=$custom->join(" right join ys_400tel on ys_400tel.cid=ys_custom.id ")->where($condition)->count();
        $tel400List=$custom->join(" right join ys_400tel on ys_400tel.cid=ys_custom.id ")->where($condition)->page($pagenum)->order('ys_400tel.id desc')->limit($pagsize)->select();
        //echo $custom->getLastSql();
        $page=new Page($totalnum,$pagsize);
        $page->rollPage=$pagsize;
        $page->setConfig("prev","上一页");
        $page->setConfig("next","下一页");
        $page->setConfig("first","首页");
        $page->setConfig("last","末页");
        $page->setConfig("theme","共%totalRow%%header%条数据 %nowPage%/%totalPage%页  %first% %upPage%   %linkPage%  %downPage% %end%");

        unset($data);
        $pageshow = $page->show();
        $this->assign("pageshow", $pageshow);


        $this->tel400List=$tel400List;
        $this->display();
    }

    public function websites()
    {
        Load('extend');
        $custom=M("custom");

        $condition["type"]=2;
        $huifangdata = $this->CacheArray("huifang", 'yewuid',$condition);
        $this->huifangdata = $huifangdata;

        $xufeidata = $this->CacheArray("xufei", 'yewuid',$condition);
        $this->xufeidata = $xufeidata;

        unset($condition);

        $query_userName = I("get.query_userName", "");
        if($query_userName=="0")
            $query_userName='';

        if (!mb_check_encoding($query_userName, 'utf-8')){
            $query_userName = iconv('gb2312', 'utf-8', $query_userName);
        }

        $query_sdate=I("get.query_sdate","1970-1-1");
        $query_edate=I("get.query_edate",date("Y-m-d H:i:s"));

        $this->query_userName=$query_userName;
        if($query_sdate!="0")
            $this->query_sdate=I("get.query_sdate");
        if($query_edate!="0")
            $this->query_edate=I("get.query_edate");

        if($query_sdate=="0")
            $query_sdate='1970-1-1';
        if($query_edate=="0")
            $query_edate= date("Y-m-d H:i:s");

        $query_isgiveup = I("get.query_isgiveup", 0);
        $condition["ys_website.isgiveup"]=$query_isgiveup;
        $this->query_isgiveup=$query_isgiveup;

        if(!empty($query_userName))
        {
            $condition["company|cname"]=  array("exp", "like '%$query_userName%'"); ;
            $this->query_userName = $query_userName;
        }

        $condition['_string'].=" to_days(signdate)>=to_days('$query_sdate') and to_days(signdate)<=to_days('$query_edate')";
        // $tel400List=$custom->join(" right join ys_400tel on ys_400tel.cid=ys_custom.id ")->where($condition)->select();
        $userid = I("session.userid");
        $condition["adduser"]=$userid;
        if($userid=="16")
            $condition["adduser"]=17;

        $pagenum = I("get.p");
        import("ORG.Util.Page");
        $pagsize=M('employee')->where('id='.I("session.userid"))->getField("pagesize");
        $totalnum=$custom->join(" right join ys_website on ys_website.cid=ys_custom.id ")->where($condition)->count();
        $websiteList=$custom->join(" right join ys_website on ys_website.cid=ys_custom.id ")->where($condition)->page($pagenum)->order('ys_website.id desc')->limit($pagsize)->select();
        //echo $custom->getLastSql();
        $page=new Page($totalnum,$pagsize);
        $page->rollPage=$pagsize;
        $page->setConfig("prev","上一页");
        $page->setConfig("next","下一页");
        $page->setConfig("first","首页");
        $page->setConfig("last","末页");
        $page->setConfig("theme","共%totalRow%%header%条数据 %nowPage%/%totalPage%页  %first% %upPage%   %linkPage%  %downPage% %end%");

        unset($data);
        $pageshow = $page->show();
        $this->assign("pageshow", $pageshow);


        $this->websiteList=$websiteList;
        $this->display();
    }

    public function youhua()
    {
        Load('extend');
        $custom=M("custom");

        $condition["type"]=3;
        $huifangdata = $this->CacheArray("huifang", 'yewuid',$condition);
        $this->huifangdata = $huifangdata;

        $xufeidata = $this->CacheArray("xufei", 'yewuid',$condition);
        $this->xufeidata = $xufeidata;

        unset($condition);

        $query_userName = I("get.query_userName", "");
        if($query_userName=="0")
            $query_userName='';

        if (!mb_check_encoding($query_userName, 'utf-8')){
            $query_userName = iconv('gb2312', 'utf-8', $query_userName);
        }

        $query_sdate=I("get.query_sdate","1970-1-1");
        $query_edate=I("get.query_edate",date("Y-m-d H:i:s"));

        $this->query_userName=$query_userName;
        if($query_sdate!="0")
            $this->query_sdate=I("get.query_sdate");
        if($query_edate!="0")
            $this->query_edate=I("get.query_edate");

        if($query_sdate=="0")
            $query_sdate='1970-1-1';
        if($query_edate=="0")
            $query_edate= date("Y-m-d H:i:s");

        $query_isgiveup = I("get.query_isgiveup", 0);
        $condition["ys_youhua.isgiveup"]=$query_isgiveup;
        $this->query_isgiveup=$query_isgiveup;

        $condition['ys_youhua.type']=3;

        if(!empty($query_userName))
        {
            $condition["company|cname"]=  array("exp", "like '%$query_userName%'"); ;
            $this->query_userName = $query_userName;
        }

        $condition['_string'].=" to_days(signdate)>=to_days('$query_sdate') and to_days(signdate)<=to_days('$query_edate')";
        // $tel400List=$custom->join(" right join ys_400tel on ys_400tel.cid=ys_custom.id ")->where($condition)->select();
        $userid = I("session.userid");
        $condition["adduser"]=$userid;
        if($userid=="16")
            $condition["adduser"]=17;

        $pagenum = I("get.p");
        import("ORG.Util.Page");
        $pagsize=M('employee')->where('id='.I("session.userid"))->getField("pagesize");
        $totalnum=$custom->join(" right join ys_youhua on ys_youhua.cid=ys_custom.id ")->where($condition)->count();
        $youhuaList=$custom->join(" right join ys_youhua on ys_youhua.cid=ys_custom.id ")->where($condition)->page($pagenum)->order('ys_youhua.id desc')->limit($pagsize)->select();
        //echo $custom->getLastSql();
        $page=new Page($totalnum,$pagsize);
        $page->rollPage=$pagsize;
        $page->setConfig("prev","上一页");
        $page->setConfig("next","下一页");
        $page->setConfig("first","首页");
        $page->setConfig("last","末页");
        $page->setConfig("theme","共%totalRow%%header%条数据 %nowPage%/%totalPage%页  %first% %upPage%   %linkPage%  %downPage% %end%");

        unset($data);
        $pageshow = $page->show();
        $this->assign("pageshow", $pageshow);


        $this->youhuaList=$youhuaList;
        $this->display();
    }

    public function yishangtong()
    {
        Load('extend');
        $custom=M("custom");

        $condition["type"]=4;
        $huifangdata = $this->CacheArray("huifang", 'yewuid',$condition);
        $this->huifangdata = $huifangdata;

        $xufeidata = $this->CacheArray("xufei", 'yewuid',$condition);
        $this->xufeidata = $xufeidata;

        unset($condition);

        $query_userName = I("get.query_userName", "");
        if($query_userName=="0")
            $query_userName='';

        if (!mb_check_encoding($query_userName, 'utf-8')){
            $query_userName = iconv('gb2312', 'utf-8', $query_userName);
        }

        $query_sdate=I("get.query_sdate","1970-1-1");
        $query_edate=I("get.query_edate",date("Y-m-d H:i:s"));

        $this->query_userName=$query_userName;
        if($query_sdate!="0")
            $this->query_sdate=I("get.query_sdate");
        if($query_edate!="0")
            $this->query_edate=I("get.query_edate");

        if($query_sdate=="0")
            $query_sdate='1970-1-1';
        if($query_edate=="0")
            $query_edate= date("Y-m-d H:i:s");

        $query_isgiveup = I("get.query_isgiveup", 0);
        $condition["ys_youhua.isgiveup"]=$query_isgiveup;
        $this->query_isgiveup=$query_isgiveup;

        $condition['ys_youhua.type']=4;

        if(!empty($query_userName))
        {
            $condition["company|cname"]=  array("exp", "like '%$query_userName%'"); ;
            $this->query_userName = $query_userName;
        }

        $condition['_string'].=" to_days(signdate)>=to_days('$query_sdate') and to_days(signdate)<=to_days('$query_edate')";
        // $tel400List=$custom->join(" right join ys_400tel on ys_400tel.cid=ys_custom.id ")->where($condition)->select();
        $userid = I("session.userid");
        $condition["adduser"]=$userid;
        if($userid=="16")
            $condition["adduser"]=17;

        $pagenum = I("get.p");
        import("ORG.Util.Page");
        $pagsize=M('employee')->where('id='.I("session.userid"))->getField("pagesize");
        $totalnum=$custom->join(" right join ys_youhua on ys_youhua.cid=ys_custom.id ")->where($condition)->count();
        $youhuaList=$custom->join(" right join ys_youhua on ys_youhua.cid=ys_custom.id ")->where($condition)->page($pagenum)->order('ys_youhua.id desc')->limit($pagsize)->select();
        //echo $custom->getLastSql();
        $page=new Page($totalnum,$pagsize);
        $page->rollPage=$pagsize;
        $page->setConfig("prev","上一页");
        $page->setConfig("next","下一页");
        $page->setConfig("first","首页");
        $page->setConfig("last","末页");
        $page->setConfig("theme","共%totalRow%%header%条数据 %nowPage%/%totalPage%页  %first% %upPage%   %linkPage%  %downPage% %end%");

        unset($data);
        $pageshow = $page->show();
        $this->assign("pageshow", $pageshow);


        $this->youhuaList=$youhuaList;
        $this->display();
    }

    public function addyewu()
    {
        $type=$_GET['type'];
        $pagename="add400tel";
        $table="400tel";
        $listname="tel400";
        switch($type)
        {
            case "1":
                $pagename="add400tel";
                $table="400tel";
                $listname="tel400";
                break;
            case "2";
                $pagename="addwebsite";
                $table="website";
                $listname="website";
                break;
            case "3";
                $pagename="addyouhua";
                $table="youhua";
                $listname="youhua";
                break;
            case "4";
                $pagename="addyishangtong";
                $table="youhua";
                $listname="yishangtong";
                break;
        }

        $id=$_GET['id'];
        if($id!='')   //如果编辑的话
        {
            $this->action="edit";
            $tabledata=M($table);
            $data_Item=$tabledata->where("id=$id")->find();

            $this->$listname=$data_Item;
        }
        else
        {
            $this->action="add";
        }

       //搜索 客户/公司 信息
        $cid=$_GET['cid'];
        $custom=M("custom");
        $custom_item=$custom->where("id=$cid")->find();
        $this->custom=$custom_item;

        $this->display($pagename);
    }

    public function closeyewu()
    {
        $type=$_GET['type'];
        $cid=$_GET['cid'];
        $tablename="400tel";
        $lieming="400tel";
        switch($type)
        {
            case "1":
                $tablename="400tel";
                $lieming="400tel";
                break;
            case "2";
                $tablename="website";
                $lieming="website";
                break;
            case "3";
                $tablename="youhua";
                $lieming="youhua";
                break;
            case "4";
                $tablename="youhua";
                $lieming="yishangtong";
                break;
        }

        $custombusiness=M("custombusiness");
        $data_business = array($lieming => "0");
        $custombusiness->where("cid=$cid")->save($data_business);

        $table = M($tablename);
        $data = array('isgiveup' => "1");
        $table->where("cid=$cid")->save($data); // 根据条件保存修改的数据
        $this->success('操作成功');
    }

    public function saveyewu()
    {
        $type=$_GET['type'];
        $liename="add400tel";
        $tablename="400tel";
        switch($type)
        {
            case "1":
                $liename="400tel";
                $tablename="400tel";
                break;
            case "2";
                $liename="website";
                $tablename="website";
                break;
            case "3";
                $liename="youhua";
                $tablename="youhua";
                break;
            case "4";
                $liename="yishangtong";
                $tablename="youhua";
                break;
        }

        $table = D($tablename); // 实例化模型类
        $data = $table->create();

        $data["cid"]=I('post.cid');
        $custombusiness=D('custombusiness');//实例化模型类
        $tempbusiness=$custombusiness->find( $data["cid"]);
        $data_business = $custombusiness->create();

        $myinfo = I("session.my_info");

        $action=I('post.action');
        if($action=="add")
        {
            $data["isgiveup"]=0;
            $data["createdate"]=date("Y-m-d H:i:s");
            //添加400电话信息
            if (!$table->add($data))
            {
                $this->error("提交失败");
            }
        }
        else
        {
            $result=$table->save($data);
            if(false===$result)
            {
                $this->error("提交失败");
            }
        }

        //开通客户400业务
        if($tempbusiness==null)
        {
            $data_business[$liename]=1;
            $custombusiness->add($data_business);
        }
        else
        {
            $tempbusiness[$liename]=1;
            if(false===$custombusiness->save($tempbusiness))
            {
                $this->error("提交失败1");
            }
        }

        $this->show('<script type="text/javascript" src="__PUBLIC__/libs/js/jquery.js"></script>
	   <script type="text/javascript">
	   $(function(){
		   top.Dialog.alert("成功提交",function(){
			   window.parent.frmright.location.reload();
			   top.Dialog.close()
	   })})</script>
	   ', 'utf-8');
    }

    public function yewugiveup()
    {
        $id = I("get.id");
        $cid = I("get.cid");

        $type=$_GET['type'];
        $tablename="400tel";
        $lieming="400tel";
        switch($type)
        {
            case "1":
                $tablename="400tel";
                $lieming="400tel";
                break;
            case "2";
                $tablename="website";
                $lieming="website";
                break;
            case "3";
                $tablename="youhua";
                $lieming="youhua";
                break;
            case "4";
                $tablename="youhua";
                $lieming="yishangtong";
                break;
        }

        $table = M($tablename);
        $data = array('isgiveup' => "1");
        $table->where("id=$id")->save($data); // 根据条件保存修改的数据

        $yewuList=$table->where("cid=$cid and isgiveup=0")->select();
        //如果该用户的该业务信息 全都放弃，则关闭该用户的该业务
        if($yewuList==null)
        {
            $custombusiness=M("custombusiness");
            $data_business = array($lieming => "0");
            $custombusiness->where("cid=$cid")->save($data_business);
        }

        $this->success('放弃成功');
    }

    public function edithuifang()
    {
        $yewuid=$_GET["id"];
        $type=$_GET['type'];

        $con['yewuid'] = $yewuid;
        $con['type']=$type;

        $account = M('huifang'); // 实例化模型类
        import("ORG.Util.Page");
        $pagsize = 15;
        $totalnum = $account->where($con)->count();
        $list = $account->where($con)->page($_GET['p'])->order('id desc')->limit($pagsize)->select();

        $this->assign('yewuid', $yewuid);
        $this->assign('type', $type);
        $this->assign("accounts_list", $list);

        $page = new Page($totalnum, $pagsize);
        $page->rollPage = $pagsize;
        $page->setConfig("prev", "上一页");
        $page->setConfig("next", "下一页");
        $page->setConfig("first", "首页");
        $page->setConfig("last", "末页");
        $page->setConfig("theme", "共%totalRow%%header%条数据 %nowPage%/%totalPage%页  %first% %upPage%   %linkPage%  %downPage% %end%");
        $pageshow = $page->show();
        $this->assign("pageshow", $pageshow);

        $this->display();
    }

    public function savehuifang()
    {
        $newhuifang = D('huifang'); // 实例化模型类
        $data=$newhuifang->create();
        if(!$data)
        {
            $this->error($newhuifang->getError());
        }
        $data['yewuid'] = $_GET['id'];
        $data['type'] = $_GET['type'];
        $data['createdate']=date("Y-m-d H:i:s");
        $newhuifang->add($data);
        $this->show('
        <script type="text/javascript" src="__PUBLIC__/libs/js/jquery.js"></script>
        <script type="text/javascript">
        $(function(){top.Dialog.alert("成功提交",function(){
        window.parent.frmright.location.reload();top.Dialog.close()
        })})</script>', 'utf-8');
    }

    public function delhuifang()
    {
        $remarks = M("huifang");
        if (!$remarks->delete($_GET['id']))
        {
            $this->error("删除失败");
        } else
        {
            $this->success("删除成功");
        }
    }

    public function editxufei()
    {
        $yewuid=$_GET["id"];
        $type=$_GET['type'];

        $con['yewuid'] = $yewuid;
        $con['type']=$type;

        $account = M('xufei'); // 实例化模型类
        import("ORG.Util.Page");
        $pagsize = 8;
        $totalnum = $account->where($con)->count();
        $list = $account->where($con)->page($_GET['p'])->order('id desc')->limit()->select();

        $this->assign('yewuid', $yewuid);
        $this->assign('type', $type);
        $this->assign("accounts_list", $list);

        $page = new Page($totalnum, $pagsize);
        $page->rollPage = $pagsize;
        $page->setConfig("prev", "上一页");
        $page->setConfig("next", "下一页");
        $page->setConfig("first", "首页");
        $page->setConfig("last", "末页");
        $page->setConfig("theme", "共%totalRow%%header%条数据 %nowPage%/%totalPage%页  %first% %upPage%   %linkPage%  %downPage% %end%");
        $pageshow = $page->show();
        $this->assign("pageshow", $pageshow);

        $this->display();
    }

    public function savexufei()
    {
        $newxufei = D('xufei'); // 实例化模型类
        $data=$newxufei->create();
        if(!$data)
        {
            $this->error($newxufei->getError());
        }
        $data['yewuid'] = $_GET['id'];
        $data['type'] = $_GET['type'];

        $yewuid=$data['yewuid'];
        $tablename="400tel";
        switch( $data['type'])
        {
            case "1":
                $tablename="400tel";
                break;
            case "2";
                $tablename="website";
                break;
            case "3";
                $tablename="youhua";
                break;
            case "4";
                $tablename="youhua";
                break;
        }
        $table=M($tablename);
        $table_data=$table->where("id=$yewuid")->find();

        $data['cid']=$table_data['cid'];
        $data['createdate']=date("Y-m-d H:i:s");
        $newxufei->add($data);
        $this->show('
        <script type="text/javascript" src="__PUBLIC__/libs/js/jquery.js"></script>
        <script type="text/javascript">
        $(function(){top.Dialog.alert("成功提交",function(){
        window.parent.frmright.location.reload();top.Dialog.close()
        })})</script>', 'utf-8');
    }

    public function delxufei()
    {
        $remarks = M("xufei");
        if (!$remarks->delete($_GET['id']))
        {
            $this->error("删除失败");
        } else
        {
            $this->success("删除成功");
        }
    }

    public function xufeilist()
    {
        $userid = I("session.userid");
        $query_type = I("get.query_type", 0);
        $query_userName = I("get.query_userName", "");

        $query_sdate=I("get.query_sdate","1970-1-1");
        $query_edate=I("get.query_edate",date("Y-m-d H:i:s"));

        if($query_sdate!="0")
            $this->query_sdate=I("get.query_sdate");
        if($query_edate!="0")
            $this->query_edate=I("get.query_edate");

        if($query_sdate=="0")
            $query_sdate='1970-1-1';
        if($query_edate=="0")
            $query_edate= date("Y-m-d H:i:s");

        switch($query_type)
        {
            case "0":break;
            case "1": $condition["ys_xufei.type"]= 1 ; break;
            case "2": $condition["ys_xufei.type"]= 2 ; break;
            case "3": $condition["ys_xufei.type"]= 3 ; break;
            case "4": $condition["ys_xufei.type"]= 4 ; break;
        }
        $this->query_type = $query_type;

        if(!empty($query_userName))
        {
            $condition["company|cname"]=  array("exp", "like '%$query_userName%'"); ;
            $this->query_userName = $query_userName;
        }
        $condition['_string'].=" to_days(xudate)>=to_days('$query_sdate') and to_days(xudate)<=to_days('$query_edate')";
        $condition["ys_custom.section"]=20;
        $condition["adduser"]=$userid;
        $condition["isgiveup"]=0;

        // $custom_list=$kefuView->field('id,cname,company,tel,400tel,website,youhua,yishangtong')->where($condition)->order("addtime desc")->select();
        $xufei=M('xufei');
        $pagenum = I("get.p");
        import("ORG.Util.Page");
        $pagsize=M('employee')->where('id='.I("session.userid"))->getField("pagesize");
        $totalnum=$xufei->join(" left join ys_custom on ys_custom.id=ys_xufei.cid")->where($condition)->count();
        $list=$xufei->join(" left join ys_custom on ys_custom.id=ys_xufei.cid")->where($condition)->page($pagenum)->order('ys_xufei.id desc')->limit($pagsize)->select();
        //echo($xufei->getLastSql());exit;
        $page=new Page($totalnum,$pagsize);
        $page->rollPage=$pagsize;
        $page->setConfig("prev","上一页");
        $page->setConfig("next","下一页");
        $page->setConfig("first","首页");
        $page->setConfig("last","末页");
        $page->setConfig("theme","共%totalRow%%header%条数据 %nowPage%/%totalPage%页  %first% %upPage%   %linkPage%  %downPage% %end%");

        unset($data);
        $pageshow = $page->show();
        $this->assign("pageshow", $pageshow);

        //$this->xufei_list=$list;
        $summoney=0;
        foreach ($list as $k => $v)
        {
            $summoney=$summoney+$v['xumoney'];
        }
        $this->summoney=$summoney;


        $this->xufei_list=$list;
        $this->display();
    }
}

?>